package com.jinsi.service.impl;

import com.jinsi.mapper.NewFeeMapper;
import com.jinsi.pojo.ScClassDocument;
import com.jinsi.pojo.ScClasses;
import com.jinsi.pojo.ScStudent;
import com.jinsi.service.NewFeeService;
import com.jinsi.utils.MapReturn;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.Map;

@Service
public class NewFeeServiceImpl implements NewFeeService {
    @Autowired
    private NewFeeMapper mapper;


    /**
     *
     * @param id
     * @return ScClasses
     * 通过班级id查询学费
     */
    @Override
    public ScClasses getClassById(Integer id) {
        ScClasses classes = mapper.getClassById(id);
        return classes;
    }


    /**
     *
     * @param name
     * @return int
     * 通过市场部名称查询市场部id
     */
    @Override
    public int getMarketingByName(String name) {
        int id = mapper.getMarketingByName(name);
        return id;
    }


    /**
     *
     * @param student
     * @throws Exception
     * 添加学生信息
     */
    @Override
    public void addScStudent(ScStudent student) throws Exception {
        int num = mapper.addScStudent(student);
        if (num == 0){
            throw new Exception();
        }
    }


    /**
     *
     * @param classDocument
     * @throws Exception
     * 添加单据分类信息
     */
    @Override
    public void addScClassDocument(ScClassDocument classDocument) throws Exception {
        int num = mapper.addScClassDocument(classDocument);
        if (num == 0){
            throw new Exception();
        }
    }


    /**
     *
     * @param id
     * @param haveFees
     * @param documentWay
     * @return Map
     * 交钱
     */
    @Override
    public Map<String, Object> haveFee(int id, BigDecimal haveFees,int documentWay) {
        try {
            mapper.haveFee(id,haveFees,documentWay);
            return MapReturn.getSuccess("交钱成功");
        }catch (Exception e){
            System.out.println("数据库有问题==========>"+e.getMessage());
            return MapReturn.getError("交钱失败");
        }
    }
}
